﻿using ShanghaiMetroAPP.Model.SMAPPControl;
using ShanghaiMetroAPP.ViewModel.SMAPPControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ShanghaiMetroAPP.SMAPPControl
{
    /// <summary>
    /// LineInfoControl.xaml 的交互逻辑
    /// </summary>
    public partial class LineInfoControl : UserControl
    {
        public LineInfoViewModel ViewModel;
        public LineInfoControl()
        {
            InitializeComponent();

            this.DataContextChanged += this.LineInfoControl_DataContextChanged;
        }

        private void LineInfoControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            //根据DataContext，解析并生成
            if (this.DataContext != null)
            {
                var model = this.DataContext as DirectionInfoListModel;
                if(model != null)
                {
                    //删除所有现存控件
                    StackPanel.Children.Clear();
                    for (var index = 0; index < model.Count; index++)
                    {
                        DirectionInfoControl control = new DirectionInfoControl();
                        
                        control.DataContext = model[index];
                        StackPanel.Children.Add(control);
                    }
                }
            }
        }
    }
}
